<%--
  Created by IntelliJ IDEA.
  User: limin
  Date: 2021/8/8
  Time: 20:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
    <base href="<%=basePath%>">

    <title></title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">

    <link rel="stylesheet" type="text/css" href="css/maintable.css" >
    <link rel="stylesheet" type="text/css" href="css/edittable.css"  >
    <link rel="stylesheet" type="text/css" href="css/validate.css"  >
    <script type="text/javascript"  src="js/jquery-1.8.0.js"></script>
    <script type="text/javascript">
        $(function(){
            $("#ch_checkall,#top_ch_checkall").click(function(){
                if(this.checked){
                    $("input[name=ck_id]").attr("checked","checked");
                }else{
                    $("input[name=ck_id]").removeAttr("checked");
                }
            });

            $("table tr").mouseover(function(){
                $(this).css("background","#D3EAEF");
                $(this).siblings().css("background","white");
            });
        });
    </script>
    <script>
        $(function (){
            $.ajax({
                type:"post",
                url:"CateServlet.do",
                data:{
                    flag: "getCate",
                    parentId:"0"
                },
                dataType:"json",
                success:function (cate){
                    $("#bigCateId").empty();
                    $("#bigCateId").append("<option value=''>==大分类==</option>");
                    $.each(cate,function (k,cate){
                        $("#bigCateId").append("<option value='"+cate.id+"'>"+cate.cateName+"</option>");
                        if(cate.id==${bigCateId}+""){
                            $("#bigCateId").val(${bigCateId});
                        }
                    })
                },
                error:function (){
                    alert("出错了")
                }
            })
        })
    </script>
    <script >
        $(function (){
            $("#bigCateId").change(function (){
                if ($("#bigCateId").val()==""){
                    $("#smallCateId").empty();
                    $("#smallCateId").append("<option value=''>==小分类==</option>");
                }else{
                    $.ajax({
                        type: "post",
                        url:"CateServlet.do",
                        data: {
                            flag:"getCate",
                            parentId: this.value
                        },
                        dataType: "json",
                        success:function (cate){
                            $("#smallCateId").empty();
                            $("#smallCateId").append("<option value=''>==小分类==</option>");
                            $.each(cate,function (k,cate){
                                $("#smallCateId").append("<option value='"+cate.id+"'>"+cate.cateName+"</option>");
                                if(cate.id==${smallCateId}+""){
                                    $("#smallCateId").val(${smallCateId});
                                }
                            })
                        }
                    })
                }
            })
        })
    </script>
    <script>
        $(function(){
            if(""!=${bigCateId}+""){
                $.ajax({
                    type:"post",
                    url:"CateServlet.do",
                    data:{
                        flag:"getCate",
                        parentId:${bigCateId}
                    },
                    async:false,
                    dataType:"json",
                    success:function(cate){
                        $("#smallCateId").empty();
                        $("#smallCateId").append("<option value=''>==小分类==</option>");
                        $.each(cate,function(k,cate){
                            $("#smallCateId").append("<option value='"+cate.id+"'>"+cate.cateName+"</option>");
                            if(cate.id==${smallCateId}+""){
                                $("#smallCateId").val(${smallCateId});
                            }
                        });
                    }
                });
            }
        });
    </script>
    <script>
        function subForm(){
            $("#pageIndex").val("1")
            document.form1.submit();
        }
    </script>
    <style>
        .div_tools {
            width: 99.5%;
            height: 28px;
            background: #D3EAEF;
            margin: 0px auto;
            margin-top: 5px;
            margin-bottom: 5px;
            font-size: 12px;
            position: relative;
        }

        .div_tools select {
            height: 22px;
            font-size: 12px;
            margin-top: 3px;
        }

        #btnsubmit {
            width: 40px;
            height: 20px;
            font-size: 12px;
        }
    </style>
</head>

<body>

<div class ="div_title">
    <div class="div_titlename"> <img src="images/san_jiao.gif" ><span>商品列表</span></div>
</div>
<form name="form1" id="form1" action="GoodsServlet.do?flag=manage" method="post">
    <div class="div_tools">
        <select name="bigCateId" id="bigCateId">
        </select>
        <select name="smallCateId" id="smallCateId">
            <option value=''>==小分类==</option>
        </select>
        <span>商品名称：</span>
        <input type="text" name="goodsName" value="${goodsName}">
        <input type="submit" value="查询" onclick="subForm()">
    </div>
<table class="main_table">
    <tr>
        <th><input type="checkbox" id="ch_checkall" /></th>	<th>名称</th> 	<th>单位</th>	<th>单价</th>  <th>大分类</th>  <th>小分类</th>	<th>操作</th>
    </tr>
    <c:forEach var="goods" items="${goodsList}">
        <tr>
            <td>
                <input type="checkbox" name="ck_id" value="69" />
            </td>
            <td>${goods.goodsName}</td>
            <td>${goods.unit}</td>
            <td>${goods.price}</td>
            <c:forEach var="cate" items="${cateInfoList}">
                <c:if test="${goods.bigCateId == cate.id}">
                    <td>${cate.cateName}</td>
                </c:if>
            </c:forEach>
            <c:forEach var="cate" items="${cateInfoList}">
                <c:if test="${goods.smallCateId == cate.id}">
                    <td>${cate.cateName}</td>
                </c:if>
            </c:forEach>
            <td>
                <a href="goods/goods_details.jsp?id=${goods.id}">
                    查看
                </a> |
                <a href="goods/goods_update.jsp?id=${goods.id}">
                    修改
                </a> |
                <a href="GoodsServlet.do?flag=deleteGoods&id=${goods.id}&pageIndex=${page.pageIndex}&bigCateId=${bigCateId}&smallCateId=${smallCateId}&goodsName=${goodsName}" onclick="return confirm('确认删除商品吗')">
                    删除
                </a>
            </td>
        </tr>
    </c:forEach>
</table>

<div class="div_page" >
    <div class="div_page_left">    共有 <label>${page.rowCount }</label> 条记录，当前第 <label>${page.pageIndex }</label> 页，共 <label>${page.pageCount } 页</label> 页	</div>
    <div class="div_page_right" >
        <c:if test="${page.pageIndex != 1 }">
            <a href="GoodsServlet.do?flag=manage&bigCateId=${bigCateId}&smallCateId=${smallCateId}&goodsName=${goodsName}&pageIndex=1">
                首页
            </a>
            <a href="GoodsServlet.do?flag=manage&bigCateId=${bigCateId}&smallCateId=${smallCateId}&goodsName=${goodsName}&pageIndex=${ page.pageIndex-1 }">
                上一页
            </a>
        </c:if>
        <c:if test="${page.pageIndex != page.pageCount }">
            <a href="GoodsServlet.do?flag=manage&bigCateId=${bigCateId}&smallCateId=${smallCateId}&goodsName=${goodsName}&pageIndex=${ page.pageIndex+1 }">
                下一页
            </a>
            <a href="GoodsServlet.do?flag=manage&bigCateId=${bigCateId}&smallCateId=${smallCateId}&goodsName=${goodsName}&pageIndex=${page.pageCount }">
                尾页
            </a>
        </c:if>
        <button>转到</button>
        <input type="text" name="pageIndex" id="pageIndex" value="${page.pageIndex }" > 页
    </div>

</div>
</form>
</body>
</html>
